from datetime import datetime
def printRecord():
    for item in headerList:
        print("%-12s" % item, end="")
    print("\n")
    for item in recordList:
        for item1 in item:
            print("%-12s"%item1,end="")
        print("\n")

def getDateFormat():
    current_date = datetime.now()
    formatted_date = current_date.strftime('%Y-%m-%d')
    return  formatted_date

def addAccount():
    ID = len(recordList)+1
    category = input("请输入添加的类别\n")
    account = input("请输入账户\n")
    money = input("请输入金额\n")
    date = getDateFormat()
    statement = input("请输入说明\n")
    arr=[ID,category,account,money,date,statement]
    recordList.append(arr)
    print("添加成功")
    printRecord()

def editAccount(ID):
    index=1
    for item in headerList:
        print("%s.%s   "%(index,item))
        index+=1
    num=eval(input("请输入需要编辑的列"))
    num-=1
    print(num)
    for item in recordList:
        if item[0]==ID:
            # print(item[num])
            item[num]=input("请输入修改的值")
            print("修改成功")
            # printRecord()
def delAccount(ID):
    index=0
    for item in recordList:
        if item[0] == ID:
            del recordList[index]
            print("删除成功")
            # printRecord()
        index+=1

def getAccount(ID):
    for item in recordList:
        if item[0] == ID:
            print(item)
            print("查询成功")
def login(username,password):
    if username==user["username"] and password==user["password"]:
        return 1
    elif username==admin["username"] and password==admin["password"]:
        return 2
    return 3

if __name__ == '__main__':
    headerList = ["ID", "类别", "账户", "金额", "时间", "说明"]
    recordList=[[1,"吃饭支出","交通银行",247.0,"2016-03-02","家庭聚餐"],[2,"工资收入","现金",12345.0,"2016-03-15","开工资了"],[3,"买衣服","现金",1234.0,"2016-03-21","买衣服"],[4,"吃饭","现金",34.0,"2016-03-21","吃饭"],[5,"理发","现金",30.0,"2016-03-21","理发"]]
    user={"username":"lisi","password":"123456"}
    admin={"username":"admin","password":"123456"}
    while True:
        username=input("请输入用户名：")
        password=input("请输入密码：")
        result=login(username,password)
        if result==1:
            print("用户登录成功")
            while True:
                print("1.查询所有  2.条件查询")
                choice = eval(input())
                if choice == 1:
                    printRecord()
                elif choice == 2:
                    print("1.查询账务 2.退出系统")
                    choice = eval(input("请输入要操作的功能序号[1-2]"))
                    if choice == 1:
                        ID = eval(input("请输入查询的账务ID\n"))
                        getAccount(ID)
                    elif choice==2:
                        break
        elif result == 2:
            print("管理员登录成功")
            while True:
                print("1.查询所有  2.条件查询")
                choice = eval(input())
                if choice == 1:
                    printRecord()
                elif choice == 2:
                    print("1.添加账务  2.编辑账务  3.删除账务  4.查询账务 5.退出系统")
                    choice = eval(input("请输入要操作的功能序号[1-5]"))
                    if choice == 1:
                        addAccount()
                    elif choice == 2:
                        ID = eval(input("请输入编辑的账务ID\n"))
                        editAccount(ID)
                    elif choice == 3:
                        ID = eval(input("请输入删除的账务ID\n"))
                        delAccount(ID)
                    elif choice == 4:
                        ID = eval(input("请输入查询的账务ID\n"))
                        getAccount(ID)
                    elif choice == 5:
                        break
        elif result==3:
            print("账户或密码错误，请重新输入")